﻿<Window x:Class="OneStopProgrammingMatrix.Views.OSPMatrix"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:convlocal="clr-namespace:OneStopProgrammingMatrix.Converters"
        xmlns:conv="clr-namespace:CommonUtilities.Converters;assembly=CommonUtilities"
        xmlns:vm="clr-namespace:OneStopProgrammingMatrix.ViewModels"
        xmlns:vw="clr-namespace:OneStopProgrammingMatrix.Views"
        xmlns:cutilctrl="clr-namespace:CommonUtilities.Controls;assembly=CommonUtilities"
        Title="{Binding Title, FallbackValue='&lt;Title&gt;'}" 
        WindowStyle="None" WindowStartupLocation="CenterScreen"
        MinHeight="350" MinWidth="625" Height="350" Width="625" 
        PreviewKeyDown="Window_PreviewKeyDown" Icon="/OneStopProgrammingMatrix;component/Images/OSPMatrix.ico">
    <Window.Resources>
        <conv:UIOffsetConverter x:Key="UIOffsetConverter" />
        <!--<conv:VisibilityConverter x:Key="VisibilityConverter" />-->
        <convlocal:VisibilityConverter x:Key="VisibilityConverter" />
        <convlocal:MatrixGroupMnemonicConverter x:Key="MatrixGroupMnemonicConverter" />
        <convlocal:MatrixItemMnemonicConverter x:Key="MatrixItemMnemonicConverter" />
    </Window.Resources>

    <Border Name="brdMainMNargin" BorderBrush="Gray" BorderThickness="1">
        <Grid Name="MainLayout" Margin="5">
            <Grid Name="grdAddNewItem" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="LightGreen"
                  Visibility="{Binding IsAddNewVisible, Converter={StaticResource VisibilityConverter}, ConverterParameter=C}">
                <!--<vw:AddNewItem x:Name="vwAddNewItem" Margin="50,0" />-->
            </Grid>

            <Grid Name="grdControls" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                  Visibility="{Binding IsAddNewVisible, Converter={StaticResource VisibilityConverter}, ConverterParameter=-C}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <Border Name="brdTitle" Grid.Row="0" Grid.ColumnSpan="2" Style="{StaticResource TitleBackgroundStyle}"
                        MouseLeftButtonDown="brdTitle_MouseLeftButtonDown">
                    <Grid Name="grdTitle">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <TextBlock Name="txtbTitle" Style="{StaticResource TitleTextStyle}"
                                   Text="{Binding Title, FallbackValue=&lt;Title&gt;}" />
                        <Expander Name="tglShowSettings" Grid.Column="1" Height="23" Width="23" Margin="5" />
                        <StackPanel Grid.Column="2" Orientation="Horizontal">
                            <Button Name="btnAddItem" Content="+ Add" VerticalAlignment="Center" Padding="10,2"
                                    Command="{Binding OpenUpdaterCommand}" CommandParameter="{x:Static vm:eUpdateMode.Add}" />
                            <Button Name="btnEditItem" Content="+ Edit" VerticalAlignment="Center" Padding="10,2"
                                    Command="{Binding OpenUpdaterCommand}" CommandParameter="{x:Static vm:eUpdateMode.Edit}" />
                        </StackPanel>

                        <StackPanel Name="stkTitle" Grid.Column="3" Margin="10,2" HorizontalAlignment="Right" Orientation="Horizontal">
                            <TextBlock Name="lblSearch" Margin="5,0" Text="Search" Foreground="White" VerticalAlignment="Center" />
                            <cutilctrl:CUtil_WatermarkTextBox Name="txtSearch" Width="150" VerticalAlignment="Center" 
                                                              WatermarkText="&lt;Search by keyword&gt;" WatermarkAlignment="Left">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="TextChanged">
                                        <i:InvokeCommandAction Command="{Binding SearchCommand}" 
                                                               CommandParameter="{Binding ElementName=txtSearch, Path=Text}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </cutilctrl:CUtil_WatermarkTextBox>
                            <Border Name="brdSearch" BorderBrush="White" Margin="2" Height="22" BorderThickness="1" CornerRadius="2">
                                <Image Name="imgSearch" Stretch="Fill" Source="/OneStopProgrammingMatrix;component/Images/search.jpg" />
                            </Border>
                        </StackPanel>
                    </Grid>
                </Border>

                <Border Grid.Row="1" Grid.ColumnSpan="2" Margin="0,-2.5,0,5" Padding="5,3" 
                        CornerRadius="0,0,5,5" BorderThickness="1,0,1,1" BorderBrush="Blue" 
                        Visibility="{Binding ElementName=tglShowSettings, Path=IsExpanded, Converter={StaticResource VisibilityConverter}, ConverterParameter=C}">
                    <StackPanel Name="stkOptions" Orientation="Horizontal">
                        <ToggleButton Name="tglViewType" Height="23" Width="23" HorizontalContentAlignment="Center" Style="{StaticResource ToggleDisplayViewStyle}" 
                                      IsChecked="{Binding IsGroupingAllowed, Mode=TwoWay}" />
                        <TextBlock Name="txtbGrouping" Margin="3,0" Text="Allow grouping?" />
                        <Expander Name="expGrouping" Width="23" IsExpanded="{Binding IsExpanded}" 
                                  Visibility="{Binding IsGroupingAllowed, Converter={StaticResource VisibilityConverter}, ConverterParameter=-H}" />
                        <Border Style="{StaticResource SeparatorStyle}" />

                        <CheckBox Name="chkSortAsc" Content="Sort asccending?" IsChecked="{Binding IsSortAscending, Mode=TwoWay}" />
                        <Border Style="{StaticResource SeparatorStyle}" />
                        <CheckBox Name="chkAllowEmpty" Content="Keep empty items?" IsChecked="{Binding IsEmptyAllowed, Mode=TwoWay}" />
                        <Border Style="{StaticResource SeparatorStyle}" />
                        <CheckBox Name="chkDefaultFirst" IsChecked="{Binding IsDefaultFirst, Mode=TwoWay}" 
                                  IsEnabled="{Binding ElementName=chkAllowEmpty, Path=IsChecked}" 
                                  Checked="chkDefaultFirst_CheckedChanged" Unchecked="chkDefaultFirst_CheckedChanged" />
                    </StackPanel>
                </Border>

                <ScrollViewer Name="scrlContent" Grid.Row="2" Grid.ColumnSpan="2">
                    <Grid>
                        <ListBox Name="lstLinks" Width="{Binding ElementName=MainLayout, Path=Width}" 
                                 ItemsSource="{Binding AllLinks}" SelectedValuePath="Name" Style="{StaticResource MatrixItemStyle}"
                                 Visibility="{Binding IsGroupingAllowed, Converter={StaticResource VisibilityConverter}, ConverterParameter=C}" />
                        <ItemsControl Name="itmctrlLinks" ItemsSource="{Binding AllLinksGrouped}" 
                                      Visibility="{Binding IsGroupingAllowed, Converter={StaticResource VisibilityConverter}, ConverterParameter=-C}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Expander Name="expGroupName" Header="{Binding MatrixGroup, Converter={StaticResource MatrixGroupMnemonicConverter}}" IsExpanded="{Binding IsGroupOpen, Mode=TwoWay}">
                                        <ListBox Name="lstLinksGr" Style="{StaticResource MatrixItemStyle}" 
                                                 SelectedValuePath="Name" ItemsSource="{Binding MatrixItems}">
                                            <ListBox.ItemTemplate>
                                                <DataTemplate>
                                                    <Button Name="btnOpenPath" Margin="5,2" Width="150" FontWeight="Bold"
                                                            HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="Red"
                                                            HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
                                                            Command="{Binding DataContext.OpenLinkCommand, RelativeSource={RelativeSource AncestorType=ItemsControl, AncestorLevel=2, Mode=FindAncestor}}" 
                                                            CommandParameter="{Binding Path}">
                                                        <!--RKD-->
                                                        <Button.Content>
                                                            <MultiBinding Converter="{StaticResource MatrixItemMnemonicConverter}">
                                                                <Binding Path="Name" />
                                                                <Binding Path="MatrixGroup" />
                                                            </MultiBinding>
                                                        </Button.Content>
                                                        <!--<Button.ToolTip>
                                                            <Border CornerRadius="5">
                                                                <TextBlock>
                                                                    <Run Text="{Binding Name, StringFormat='Click to open &quot;{0}&quot;&#x0a;'}" />
                                                                    <Run Text="{Binding Description, StringFormat='{}{0}&#x0a;'}" FontStyle="Italic" />
                                                                    <Run Text="( " />
                                                                    <Hyperlink NavigateUri="{Binding BUri}">
                                                                        <Run Text="{Binding Path, StringFormat='{}{0}'}"/>
                                                                    </Hyperlink>
                                                                    <Run Text=" )" />
                                                                </TextBlock>
                                                            </Border>
                                                        </Button.ToolTip>
                                                        <Button.Content>
                                                            <MultiBinding Converter="{StaticResource MatrixItemMnemonicConverter}">
                                                                <Binding Path="Name" />
                                                                <Binding Path="MatrixGroup" />
                                                            </MultiBinding>
                                                        </Button.Content>
                                                        <Button.ContextMenu>
                                                            <ContextMenu>
                                                                <MenuItem Name="mnuEdit" Header="Edit" />
                                                                <MenuItem Name="mnuDelete" Header="Delete" />
                                                            </ContextMenu>
                                                        </Button.ContextMenu>-->
                                                    </Button>
                                                </DataTemplate>
                                            </ListBox.ItemTemplate>
                                        </ListBox>
                                    </Expander>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </Grid>
                </ScrollViewer>
            </Grid>
        </Grid>
    </Border>
</Window>
